package com.developer.platform.application.command;

import cn.hutool.core.bean.BeanUtil;
import com.developer.platform.application.command.cmd.MenuAdd;
import com.developer.platform.application.command.cmd.MenuUpdate;
import com.developer.platform.domain.Menu;
import com.developer.platform.domain.service.IMenuService;
import org.springframework.stereotype.Component;

/**
 * @author ：qiaoliang
 * @date ：2020-11-09
 */
@Component
public class MenuCmdManager {

    private final IMenuService menuService;

    public MenuCmdManager(IMenuService menuService) {
        this.menuService = menuService;
    }

    /**
     *  新增资源信息
     *
     * @author ：qiaoliang
     * @param menuAdd : 资源信息
     * @date 2020-10-20 09:45
     */
    public void  save(MenuAdd menuAdd){
        Menu menu = new Menu();
        BeanUtil.copyProperties(menuAdd, menu);
        menuService.save(menu);
    }

    /**
     *  修改资源基础信息
     *
     * @author ：qiaoliang
     * @param id :  资源主键
     * @param menuUpdate : 修改信息
     * @date 2020-10-20 10:23
     */
    public void update(long id , MenuUpdate menuUpdate){
        Menu menu = new Menu(id);
        BeanUtil.copyProperties(menuUpdate, menu);
        menuService.updateInfo(menu);
    }

    /**
     *  删除资源信息
     *
     * @author ：qiaoliang
     * @param id :  资源ID
     * @date 2020-10-20 09:56
     */
    public void deleteById(long id){
        menuService.delete(id);
    }

}
